/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.dahg.project.istu.controller.model;

import java.util.List;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

/**
 *
 * @author dahg
 */
@Entity
@Table(name="menu")
public class Menu {
    
    @Id
    private String id;
    private String descripcion;
    private String icon;
    private String target;
    
    @ManyToOne
    @JoinColumn(name = "fk_padre")
    private Menu padre;
    
    @OneToMany(mappedBy = "padre")
    @LazyCollection(LazyCollectionOption.TRUE)
    private List<Menu> hijos;

    @ManyToMany(mappedBy="menus")
    private List<Rol> roles;
    
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        this.descripcion = descripcion;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getTarget() {
        return target;
    }

    public void setTarget(String target) {
        this.target = target;
    }

    public Menu getPadre() {
        return padre;
    }

    public void setPadre(Menu padre) {
        this.padre = padre;
    }

    public List<Rol> getRoles() {
        return roles;
    }

    public void setRoles(List<Rol> roles) {
        this.roles = roles;
    }

    public List<Menu> getHijos() {
        return hijos;
    }

    public void setHijos(List<Menu> hijos) {
        this.hijos = hijos;
    }

    @Override
    public String toString() {
        return descripcion;
    }
    
    @Override
    public int hashCode() {
        int hash = 7;
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Menu other = (Menu) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }
    
    
}
